<template>

    <rx-layout>
      <div slot="center">
        <a-card :title="i18n('list.comment','OpenOffice配置')"  class="OpenOffice">
          <div style="text-align: right;padding-bottom: 10px;">
              <a-button-group>
                <a-button  @click="handleSave">{{$ti18('rxForm.saveBtn','保存')}}</a-button>
                <a-button v-if="status=='0'" type="primary" @click="handleRun">{{i18n('list.start','启动服务')}}</a-button>
                <a-button v-if="status=='1'" type="danger" @click="handleEnd">{{i18n('list.stop','停止服务')}}</a-button>
              </a-button-group>
          </div>
          <a-form-model  :form="form" :rules="rules" >

                <a-form-model-item :labelCol="labelCol1" :wrapper-col="{ span: 12 }" :label="i18n('form.installPath','安装路径')" prop="installPath">
                  <a-input :placeholder="i18n('form.installPath','安装路径')" v-model="config.installPath"/>
                  <div>{{i18n('msa.pathTips1','说明：需要在服务端安装')}}<a href="http://www.openoffice.org/">OpenOffice</a>{{i18n('msa.pathTips2','服务，并且配置以下信息，可实现在线查看Office文档。')}}</div>
                </a-form-model-item>


                <a-form-model-item :labelCol="labelCol1" :wrapper-col="{ span: 12 }" label="IP" prop="ip">
                  <a-input placeholder="127.0.0.1"  v-model="config.ip" />
                </a-form-model-item>

                <a-form-model-item :labelCol="labelCol1" :wrapper-col="{ span: 12 }" :label="i18n('form.port','端口')" prop="port">
                  <a-input placeholder="8200"  v-model="config.port" />
                </a-form-model-item>

              <a-form-model-item :labelCol="labelCol1" :wrapperCol="wrapperCol" :label="i18n('form.enabled','启用')">
                  <a-checkbox  v-model="config.enable" >
                  </a-checkbox>
              </a-form-model-item>

                <a-form-model-item :labelCol="labelCol1" :wrapperCol="wrapperCol" :label="i18n('form.autoStart','自动启动')">
                  <a-checkbox  v-model="config.autoStart"  >
                  </a-checkbox>
                </a-form-model-item>
          </a-form-model>
        </a-card>
      </div>
    </rx-layout>


</template>

<script>
  import SysOpenOfficeApi from '@/api/system/core/sysOpenOffice';
  import {BaseForm, RxDialog,RxCheckbox,RxLayout} from "@lowcode/jpaas-common-lib";

  export default {
    name: "OpenOfficeConfig",
    mixins: [BaseForm],
    components: {
      RxDialog,'rx-checkbox': RxCheckbox,RxLayout
    },
    data() {
      return {
        labelCol1:{
          span:4
        },
        config:{
            port:'',
            ip:'',
            installPath:'',
            autoStart:'',
            enable:'',
        },
        rules: {
            installPath: [{required: false, message: this.i18n('form.installPath','安装路径','input'), trigger: 'change'}],
            ip: [{required: false, message: this.i18n('form.ip','IP','input'), trigger: 'change'}],
            port: [{required: false, message: this.i18n('form.port','端口','input')  , trigger: 'change'}],
        },
          status:'',

      }
    },
    created() {
       this.getConfig();
    },
    methods: {
      i18n(name,text,key){
          return this.$ti18(name,text,"SysOpenOffice",key);
      },
      getConfig() {
          SysOpenOfficeApi.getConfig().then(res => {
            this.config=JSON.parse(res.message);
            this.handleStatus();
        })
      },
      handleSave() {
          SysOpenOfficeApi.publish(this.config);
      },
      handleRun(){
          SysOpenOfficeApi.start(this.config);
          this.status=1;
      },
      handleStatus(){
          SysOpenOfficeApi.getStatus(this.config.port.toString()).then(res=>{
            this.status=res.data;
            })
      },
      handleEnd(){
        var self_=this;
        this.$confirm({
            title: this.$ti18('rxMsa.tipsInfo','提示信息'),
            content: this.i18n('msa.stopTips','确认停止服务吗?'),
            okText: this.$ti18('rxForm.ackBtn','确认'),
            cancelText: this.$ti18('rxForm.cancelBtn','取消'),
            onOk(){
                SysOpenOfficeApi.stopService(self_.config.port.toString());
                self_.status=0;
            }
        });
      }
    }
  }
</script>

<style>
  .OpenOffice .table-operator button {
    margin-right: 10px;
    margin-bottom: 15px;
  }
  .OpenOffice .ant-table-tbody .ant-table-selection-column{
    width: 10px;
  }
  .OpenOffice .ant-table-tbody > tr > td{
    width: 30%;
  }
  .OpenOffice .ant-cell{
    margin-top: 15px;
  }
</style>